// 选中的帮派列表
var players = new Array();

/**
 * 获取图表数据
 * @param areaId
 */
function getChartData(areaId,playName) {
    player = {
        "areaId": areaId,
        "playName": playName
    }
    if (!contains(players, player)) {
        players.push(player);
    }
    $.ajax({
        url: "rank/player",
        type: "post",
        contentType: "application/json",
        data: JSON.stringify(players),
        success: function (result) {
            var map = result.data;
            genChart(map);
        }
    })
}

/**
 * 获取小区信息
 * @param serverName
 */
function getArea(serverName) {
    $.ajax({
        url:"area/list?serverName="+serverName,
        dataType:"json",
        success:function(result){
            // 清空子节点
            $('#areaList li').remove();
            var list = result.data;
            list.forEach(item => {
                fun = "javascript:getPlayerList('" + item.areaId + "');";
                var li = '<li value="' + item.areaId + '"><a href="' + fun + '">' + item.areaName + '</a></li>';
                $("#areaList").append(li);
            })
        }
    })
}

function getPlayerList(areaId) {
    $.ajax({
        url: "player/cur/"+areaId,
        type: "get",
        success: function (result) {
            var list = result.data;
            $("#playerList li").remove();
            list.forEach(item => {
                // 添加节点
                fun = "javascript:getChartData('" + areaId + "','"+ item.playName +"');";
                var li = '<li title="战力：' + item.playScore + '">' +
                    '<a href="' + fun + '">' + item.playName + '</a>' +
                    '</li>';
                $("#playerList").append(li);
            })

        }
    })
}

function clearChart() {
    players.length = 0;
    genChart();
}